/*
 * Copyright 2006 - Chris Maki
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.agoracms.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

/**	
 * Note: none of the ManyToOne references in this class (createdByUser and
 * updatedByUser) include a cascade option, therefore they are not cascaded.
 * 
 * @author chrismaki
 * 
 */
@MappedSuperclass
@EntityListeners({org.agoracms.listeners.ModelListener.class})
public abstract class ModelBase  {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    private Integer id;

    @Version
    @Column(name="version")
    private Integer version;

     // TopLinkFix
     // @ManyToOne(fetch=FetchType.LAZY)
     @ManyToOne
     @JoinColumn(name="created_by_user_id")
     private User createdByUser;

    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "date_created", nullable = false)
    private Date dateCreated;

    @Column(name = "created_at_ip")
    private String createdAtIP;

    // TODO I needed to add this cascade property to make the tests work, it may
	// be related to Hibernate bug EJB-221, check it out here:
	// http://opensource.atlassian.com/projects/hibernate/browse/EJB-221
     // TopLinkFix
     // @ManyToOne(fetch=FetchType.LAZY)
    @ManyToOne
    @JoinColumn(name="updated_by_user_id")
    private User updatedByUser;
    
    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "date_updated", nullable = false)
    private Date dateUpdated;
    
    @Column(name = "updated_at_ip")
    private String updatedAtIP;

    public Integer getId() {
        return id;
    }

    public Integer getVersion() {
        return version;
    }

    public String getCreatedAtIP() {
        return createdAtIP;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public Date getDateUpdated() {
        return dateUpdated;
    }

    public String getUpdatedAtIP() {
        return updatedAtIP;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public void setCreatedAtIP(String createdByUserIP) {
        this.createdAtIP = createdByUserIP;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public void setDateUpdated(Date dateUpdated) {
        this.dateUpdated = dateUpdated;
    }

    public void setUpdatedAtIP(String updatedByUserIP) {
        this.updatedAtIP = updatedByUserIP;
    }

	public User getCreatedByUser() {
		return createdByUser;
	}

	public void setCreatedByUser(User createdBy) {
		this.createdByUser = createdBy;
	}

	public User getUpdatedByUser() {
		return updatedByUser;
	}

	public void setUpdatedByUser(User updatedBy) {
		this.updatedByUser = updatedBy;
	}
}
